package com.hospital.service.publics.controller;

import com.hospital.service.project.model.param.ProInfoDetailsParam;
import com.hospital.service.publics.model.param.FileUploadParam;
import common.core.constant.Constant;
import common.core.util.FileUtil;
import enhance.plus.logic.LogicBaseController;
import com.hospital.service.publics.entity.PubFilePath;
import com.hospital.service.publics.entity.help.PubFilePathHelp;
import com.hospital.service.publics.model.param.PubFilePathParam;
import com.hospital.service.publics.service.PubFilePathService;
import com.hospital.service.publics.model.param.PubFilePathQueryForOneRowParam;
import com.hospital.service.publics.model.param.PubFilePathQueryPageParam;
import com.hospital.service.publics.model.vo.PubFilePathVo;
import common.core.util.CommonUtil;
import common.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import enhance.plus.logic.LogicBaseController;
import enhance.plus.util.Page;
import enhance.plus.util.PageHelper;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.File;
import java.util.HashMap;
import java.util.Map;


/**
 * 文件路径表 控制器
 *
 * @author xhl
 * @created 2020-11-10 18:42:35
 */
@Slf4j
@Validated
@RestController
@Api(tags = "文件路径表")
@RequestMapping("/publics/pubFilePath")
public class PubFilePathController extends LogicBaseController<PubFilePathService, PubFilePath> {

    @Autowired
    private PubFilePathService pubFilePathService;

    @Value("${file.fileupload}")
    private String fileTruePath;

    @ApiOperation(value = "根据传入数据标识找到本地文件路径")
    @RequestMapping(value = "/filePathGet" , method = RequestMethod.GET)
    public Result<Map<String, String>> filePathGet(@Valid @RequestParam @NotBlank(message = "传入的标识不能为空") String logo ){
        String path = pubFilePathService.getFilePath(logo);
        if(CommonUtil.isEmpty(path)) {
            path = "";
        }
        path = fileTruePath + "/" + path + "/" ;
        Map<String, String> result = new HashMap<>(8);
        result.put(Constant.FILE_NAME_SOFT, path + Constant.FILE_NAME_SOFT);
        result.put(Constant.FILE_NAME_TXT, path + Constant.FILE_NAME_TXT);
        result.put(Constant.FILE_NAME_SUPPLEMENTARY, path + Constant.FILE_NAME_SUPPLEMENTARY);
        result.put(Constant.FILE_NAME_MINIML, path + Constant.FILE_NAME_MINIML);
        return Result.success(result);
    }



    @ApiOperation(value = "文件上传接口")
    @PostMapping(value = "/fileUpload")
    public Result fileUpload(@Valid @RequestParam String url, @RequestParam MultipartFile file) {
        try {
            FileUtil.upload(file,url);
        } catch (Exception e) {
            return Result.result(-1, "上传失败");
        }
        return Result.success();
    }


}
